// Learn TypeScript:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/life-cycle-callbacks.html

import { UINames } from "../../Enums/UIEnum";
import SaveManager from "../../Managers/SaveManager";
import UIManager from "../../Managers/UIManager";
import CardManager from "../../Models/Cards/CardManager";
import GateManager from "../../Models/Gates/GateManager";
import RankManager from "../../Models/Ranks/RankManager";

const { ccclass, property } = cc._decorator;

@ccclass
export default class SettingUI extends cc.Component {
    @property([cc.Sprite])
    addSpeeds: cc.Sprite[] = [];

    currenAddSpeed: cc.Sprite;
    protected onLoad(): void {
        for (const iterator of this.addSpeeds) {
            iterator.node.active = false;
        }
    }

    protected onEnable(): void {
        this.drawAddSpeed();

    }

    drawAddSpeed() {
        var usedata = SaveManager.single.userdata;
        if (this.currenAddSpeed == null) {
            this.currenAddSpeed = this.addSpeeds[usedata.addSpeedMode];
        } else {
            this.currenAddSpeed.node.active = false;
            this.currenAddSpeed = this.addSpeeds[usedata.addSpeedMode];
        }
        this.currenAddSpeed.node.active = true;
    }



    settingClick() {
        UIManager.single.showUI(UINames.PlayerInfoUI);
    }
    siginClick() {
        UIManager.single.showUI(UINames.SigninUI);
    }
    taskClick() {
        UIManager.single.showUI(UINames.TaskUI);
    }

    resetGateClick() {
        UIManager.single.showDialog("循环后将从第1关开始，是否要进入循环？", () => {
            GateManager.single.resetGate();
        }, null, this, true);
    }

    rankClick() {

        UIManager.single.showUI(UINames.RankUI);
        RankManager.single.onUploadRank();
    }

    addSpeedClick() {
        if (!CardManager.single.isHavePerpetualCard()) {
            UIManager.single.showUI(UINames.PerpetualCardUI);
            UIManager.single.showTips("获得终身卡解锁<加速>功能。");
            return;
        }

        SaveManager.single.changeAddSpeedMode();
        this.drawAddSpeed();
    }
}
